﻿using System;
using Castle.Core.Interceptor;

namespace ObjectSync
{
    [Serializable]
    internal class RemoteObjectInterceptor: IInterceptor
    {
        
        public RemoteObjectInterceptor()
        {
                        
        }

        
        public void Intercept(IInvocation invocation)
        {
            if (NetworkManager.Instance.Communicator == null)
            {
                throw new Exception("Network not initialized");
            }

            var com = NetworkManager.Instance.Communicator;


            invocation.ReturnValue =
                ((RemoteObject)invocation.InvocationTarget).ExecuteMethod(
                invocation.TargetType.Assembly.ToString(),
                invocation.TargetType.Name,
                invocation.Method.Name,
                invocation.Arguments);

            //invocation.Proceed();
        }


    }
}
